package cn.bookCity.daoimpl;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import cn.bookCity.dao.OrderItemDao;
import cn.bookCity.domain.Orderitem;
import cn.bookCity.domain.Products;
import cn.bookCity.util.DataSourceUtil;

public class OrderItemDaoImpl implements OrderItemDao  {

	@Override
	public void InsertOrderItem(Orderitem orderitem) {
		QueryRunner qr=new QueryRunner(DataSourceUtil.getDataSource());
		try {
			String sql="insert into orderitem values(?,?,?)";
			qr.update(sql,orderitem.getOrder_id(),orderitem.getProduct_id(),orderitem.getBuynum());
		}catch (SQLException e) {
			// TODO: handle exception
			e.printStackTrace();
		}
	}

	@Override
	public List<Orderitem> getOrderItems(String id) {
		QueryRunner qr=new QueryRunner(DataSourceUtil.getDataSource());
		try {
			String sql="select *from orderitem where order_id=?";
			return qr.query(sql,new BeanListHandler<>(Orderitem.class),id);
		}catch (SQLException e) {
			// TODO: handle exception
		}
		return null;
	}

}
